package com.magenta.maxoptra.gis.distancematrix;

import com.magenta.maxoptra.gis.GeographicCoordinates;
import com.magenta.maxoptra.gis.commons.Pair;
import com.magenta.maxoptra.gis.distancematrix.iterators.AsymmetricIterator;
import junit.framework.Assert;

import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;

/**
 * @author Sergey Grachev
 */
public final class GisTestUtils {

    private GisTestUtils() {
    }

    public static void assertCoordinate(final GeographicCoordinates coordinate, final double latitude, final double longitude) {
        assertNotNull(coordinate);
        assertEquals(latitude, coordinate.getLatitude());
        assertEquals(longitude, coordinate.getLongitude());
    }

    public static void assertRoute(final Pair<? extends GeographicCoordinates, ? extends GeographicCoordinates> route,
                                   final double lat1, final double lon1, final double lat2, final double lon2) {
        final GeographicCoordinates first = route.getFirst();
        assertNotNull(first);
        assertEquals(lat1, first.getLatitude());
        assertEquals(lon1, first.getLongitude());

        final GeographicCoordinates second = route.getSecond();
        assertNotNull(second);
        assertEquals(lat2, second.getLatitude());
        assertEquals(lon2, second.getLongitude());
    }

    public static void assertIteratorIndexes(final AsymmetricIterator iterator) {
        int i = 0;
        while (iterator.hasNext()) {
            Assert.assertEquals(iterator.index(), i++);
            iterator.nextRoute();
        }
    }
}
